﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class rename_table_ProductTopic : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_EChartConfig_MainTopicDict_ProjectConfigId",
                table: "EChartConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdApiDict_MainTopicDict_TopicDictId",
                table: "MainStdApiDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdDataModelDict_MainTopicDict_TopicDictId",
                table: "MainStdDataModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdEventModelDict_MainTopicDict_TopicDictId",
                table: "MainStdEventModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdFormDict_MainTopicDict_TopicDictId",
                table: "MainStdFormDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdTableDict_MainTopicDict_TopicDictId",
                table: "MainStdTableDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdViewContainerDict_MainTopicDict_TopicDictId",
                table: "MainStdViewContainerDict");

            migrationBuilder.DropTable(
                name: "MainTopicDict");

            migrationBuilder.CreateTable(
                name: "MainProductTopic",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicCode = table.Column<string>(type: "text", nullable: false),
                    TopicName = table.Column<string>(type: "text", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    NamespaceDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainProductTopic", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainProductTopic_MainProductNamespace_NamespaceDictId",
                        column: x => x.NamespaceDictId,
                        principalTable: "MainProductNamespace",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainProductTopic_MainProductTopic_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainProductTopic",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainProductTopic_NamespaceDictId",
                table: "MainProductTopic",
                column: "NamespaceDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainProductTopic_ParentId",
                table: "MainProductTopic",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_EChartConfig_MainProductTopic_ProjectConfigId",
                table: "EChartConfig",
                column: "ProjectConfigId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdApiDict_MainProductTopic_TopicDictId",
                table: "MainStdApiDict",
                column: "TopicDictId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdDataModelDict_MainProductTopic_TopicDictId",
                table: "MainStdDataModelDict",
                column: "TopicDictId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdEventModelDict_MainProductTopic_TopicDictId",
                table: "MainStdEventModelDict",
                column: "TopicDictId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdFormDict_MainProductTopic_TopicDictId",
                table: "MainStdFormDict",
                column: "TopicDictId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdTableDict_MainProductTopic_TopicDictId",
                table: "MainStdTableDict",
                column: "TopicDictId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdViewContainerDict_MainProductTopic_TopicDictId",
                table: "MainStdViewContainerDict",
                column: "TopicDictId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_EChartConfig_MainProductTopic_ProjectConfigId",
                table: "EChartConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdApiDict_MainProductTopic_TopicDictId",
                table: "MainStdApiDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdDataModelDict_MainProductTopic_TopicDictId",
                table: "MainStdDataModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdEventModelDict_MainProductTopic_TopicDictId",
                table: "MainStdEventModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdFormDict_MainProductTopic_TopicDictId",
                table: "MainStdFormDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdTableDict_MainProductTopic_TopicDictId",
                table: "MainStdTableDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdViewContainerDict_MainProductTopic_TopicDictId",
                table: "MainStdViewContainerDict");

            migrationBuilder.DropTable(
                name: "MainProductTopic");

            migrationBuilder.CreateTable(
                name: "MainTopicDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    NamespaceDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    TopicCode = table.Column<string>(type: "text", nullable: false),
                    TopicName = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainTopicDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainTopicDict_MainProductNamespace_NamespaceDictId",
                        column: x => x.NamespaceDictId,
                        principalTable: "MainProductNamespace",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainTopicDict_MainTopicDict_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainTopicDict",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainTopicDict_NamespaceDictId",
                table: "MainTopicDict",
                column: "NamespaceDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainTopicDict_ParentId",
                table: "MainTopicDict",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_EChartConfig_MainTopicDict_ProjectConfigId",
                table: "EChartConfig",
                column: "ProjectConfigId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdApiDict_MainTopicDict_TopicDictId",
                table: "MainStdApiDict",
                column: "TopicDictId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdDataModelDict_MainTopicDict_TopicDictId",
                table: "MainStdDataModelDict",
                column: "TopicDictId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdEventModelDict_MainTopicDict_TopicDictId",
                table: "MainStdEventModelDict",
                column: "TopicDictId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdFormDict_MainTopicDict_TopicDictId",
                table: "MainStdFormDict",
                column: "TopicDictId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdTableDict_MainTopicDict_TopicDictId",
                table: "MainStdTableDict",
                column: "TopicDictId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdViewContainerDict_MainTopicDict_TopicDictId",
                table: "MainStdViewContainerDict",
                column: "TopicDictId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
